
/* 
 * File:   util.h
 * Author: jorge
 *
 * Created on May 14, 2013, 4:13 PM
 */

#ifndef UTIL_H
#define	UTIL_H

#include <list>

class Util
{
public:

    /**
     * @brief Works like  printf function and the result is copied into a buffer.
     * 
     * @param buffer where the result will be copied
     * @param format as printf format
     * @param ... var args
     */
    static void format(char* buffer, const char* format, ...);

    /**
     * @brief Gets the current date according to the format.
     * 
     * @param format Format used in strftime function.
     * @param buffer where it is copied the date
     * @param size size of the buffer
     */
    static void getDate(const char* format, char* buffer, unsigned int size);
};

/**
 * 
 * @param l list to pointers
 * releases the memory of a pointers list
 */

template<class T>
static void cleanupList(std::list<T*>& l)
{
    typename std::list<T*>::iterator it = l.begin();
    for(; it != l.end(); it++)
        delete *it;
}

#endif	/* UTIL_H */

